package com.itsu.spbspider.service.impl;

import com.itsu.spbspider.mapper.CrawlerMapper;
import com.itsu.spbspider.service.Crawler;
import com.itsu.spbspider.util.HttpUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author suben
 * @create time 2020/2/12 13:24
 */
@Service("budejieJokeCrawler")
public class BudejieJokeCrawler implements Crawler {

    @Resource
    CrawlerMapper crawlerMapper;

    @Override
    public String crawlerData(Integer crawlId) throws Exception {
        com.itsu.spbspider.entity.Crawler crawler = crawlerMapper.selectById(crawlId);
        String url = crawler.getUrl();
        String content = null;
        if ("GET".equals(crawler.getMethod().toUpperCase())) {
             content = HttpUtil.get(url);
        } else {
            content = HttpUtil.post(url);
        }
        return content;
    }
}
